Repository navigation
The shader build runs as worker processes, and no shader waits for a batch (Ocarina of Time's cold Mac map: 3,002 s to 1,298 s) - #2035
Conversation
…batch: Ocarina of Time's whole Mac map, built cold on an M5 Max with 18 cores, takes 1,298 s instead of 3,002 Each shader needs about 40 ms of dmsh_build.py's own Python, which one process runs one shader at a time under the GIL, so the cores were half idle whatever J was. A build now runs as DMSH_PROCS copies of itself (default J / 3), each building a share of a phase and staging its outputs in the same cache; the build that started them writes the library as before. Within a process the misses are translated in chunks of 8, largest first, and each shader is finished as soon as its chunk is translated, instead of every worker waiting for its batch's slowest shader. The outputs are byte-identical (all 173,316 files of the whole map, apart from the chain version); the chain version changes once.
ee028e7 to
73320a2
Compare
…ts for a batch) into best-attempt; chain 49ede9ecd9d6
…d runs as worker processes, and no shader waits for a batch (Ocarina of Time's cold Mac map: 3,002 s to 1,298 s) chain header Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Measured on a Mac with fewer cores: M3 Pro (11 cores, 5 performance + 6 efficiency), 18 GB Setup:
For scale, the full cold Mac map of chain 39eb2f781d07 (main, Not tried: other |
… nvn_handle_expr.h), wide and atomic rewrites, loop_guard, the worker-process shader build (PR seedds#2035), iOS Metal compile changes, and the chain version these sources give (dmsh_chain.h)
seedds#1901 seedds#1459 seedds#1928 seedds#1942 seedds#1940 seedds#1952 seedds#1611 seedds#2065 seedds#2083 seedds#2008 seedds#2079 seedds#2022 seedds#2075 seedds#2077 seedds#2020 seedds#2021 onto main 04811a6 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014eD437mxrMnW2UwLZhpwc7 Upstream pull requests applied in this commit (their authors' work, brought onto this tree with a three-way merge; the description is in each PR): - seedds#1459 by PromethOps (open): DM_UPSCALER=metalfx takes agl's agl_ndsr_vr.pck networks too, and a variant with no curve and no power is drawn as one colour space: Ocarina of Time's upscaler is MetalFX's - seedds#1611 by Esteban-V (open): An argument block whose only change is a uniform buffer is patched instead of encoded again - seedds#1774 by uncraftablexd (closed): Compute threads that exit before a barrier keep arriving at it, and every shader loop has a cap (GPU hang defences), chain change - seedds#1824 by cocoman93 (open): Clamp texel fetches past a sampled 2D texture's edge: no hard edge in Ocarina of Time's mist - seedds#1901 by FifteenPen (open): The game's compute dispatches with no game barrier between them run side by side (profile key dispatch_overlap, on for Ocarina of Time): Kokiri Forest GPU p50 15.63 → 14.76 ms - seedds#1928 by FeReuss (open): Ocarina of Time: enc_thread on, the replay encodes on a thread of its own - seedds#1929 by FeReuss (open): Unused border corrections are compiled out of pipelines that bind no sampler with a twin (function constant DMSH_BORDER_FC) - seedds#1930 by FeReuss (open): A float add to storage memory with no result read is one native atomic add instead of a compare-and-swap loop - seedds#1940 by uncraftablexd (open): A prewarm list's lines after its #@after_first_frame line are built after the first frame, in the background, instead of in the prepare step (issue seedds#1747) - seedds#1942 by uncraftablexd (open): Frame step: late frames with the GPU idle do not step up, and a longer hold the GPU does not explain is probed - seedds#1952 by AdyaGMD (open): Compute moves ahead of scene passes past occlusion queries and conditional rendering; clears wait across dispatches - seedds#2008 by bquilty25 (open): nvn: reactive memory watchdog, 16-way view cache, and texture upload batching - seedds#2020 by padsiwono (open): Ocarina of Time v131072: Output Native draws the full output size instead of the game's 80 % frame (`DM_OUTPUT`) - seedds#2021 by padsiwono (open): Ocarina of Time v131072 renders at the launcher's Resolution (`DM_RENDER_SIZE`), docked - seedds#2022 by sleepyeyedjoe (closed): Ocarina of Time: large models no longer go black for one frame twice, 4–5 frames apart, when the game streams new textures into them (a texture ID a shader has read keeps its read mark when it gets another texture) - seedds#2030 by humanperzeus (open): A NaN colour at alpha 0 is returned as 0, as NVIDIA's blender takes a zero factor: Ocarina of Time's white clouds over the ferns are gone - seedds#2035 by Know-It-All-Brother (open): The shader build runs as worker processes, and no shader waits for a batch (Ocarina of Time's cold Mac map: 3,002 s to 1,298 s) - seedds#2065 by Raymon82777 (closed): A vertex library with layer entry points of its own gets bases for its main0 pairs: Ocarina of Time's 230 ms camera-turn hitch in Hyrule Field goes to 39 ms - seedds#2075 by sleepyeyedjoe (closed): Ocarina of Time: a patch of scenery no longer draws dark for one frame when the game gives it a sharper texture (a pool texture the walk does not make holds a stand-in of its own colours until its first read) - seedds#2077 by roandegraaf (closed): Ocarina of Time: fix the "plaid" terrain / missing texture tiles (GPU-drawn textures now reach the storage the game copies) - seedds#2079 by uncraftablexd (open): Render pipelines that share a vertex function are taken from the archive or compiled one at a time: the AGX driver crashes in createVertexProgramVariant's completion block - seedds#2083 by FifteenPen (closed): Ocarina of Time's prewarm list gets 41 more task / mesh pipelines from later play
… nvn_handle_expr.h), wide and atomic rewrites, loop_guard, the worker-process shader build (PR seedds#2035), iOS Metal compile changes, and the chain version these sources give (dmsh_chain.h)
…build uses the cores it has: finishing a shader (the MSL rewrites, its reflection, its outputs and the cache) is Python, and the threads that did it share one GIL, so one core finished every shader while the Metal compiles they waited on left the others idle. Ocarina of Time's whole Mac map (0400486024DEC000, 42,848 shaders) on an M3 Max with 16 cores, J=16: 3,506 s with the build at 104 % CPU and 4 to 5 cores busy, 1,826 s with 16 workers; every shader restored from the cache 888 to 191 s (the PR author's runs). dmsh_build.py now finishes them in DMSH_PROCS worker processes (default J; 0 = threads, as before): forks of the build made once, after the cache check and before its first thread, so they have every table and fingerprint it read (spawned workers would run the script again, and its start clears the outputs), each with its own connection to cas.db (shader_cache.Store.forked). The build translates the batches itself and hands each shader's job to a worker; results and counts come back in batch order, so the summary, the progress file and every output are those of the threads. The next batch is handed out before this one is done (two at most), so no worker waits for a batch's slowest shader; paired vertex shaders still wait for every other shader. The workers, the batch overlap, the diagnosis and those measurements are PR #2255's. Added here: the precompiled Metal headers are made before the fork (each worker made its own, three compiles a target, in a folder nothing removed without the PR's WORK override, which is gone: Red Dead Redemption's build peaked at 1.4 GB with them, 0.8 GB now); a worker that dies stops the build with one [RED] line instead of a traceback (checked by killing one); the reference entry (A shader build's Python finishes one shader at a time), which also resolves the open note under Rewrites that try every character of a large source, Ocarina of Time's note, and the memory advice in docs/development.md. PR #2035 solved the same problem by running the build as J / 3 copies of itself (Ocarina of Time on an M5 Max 3,002 to 1,298 s; 1.41 times faster on an M3 Pro for 1.3 GB more, tobiashenn's run); side by side on one Mac it gained less (Red Dead Redemption: Mac 75 to 58 s, Mac and iOS 104 to 95 s against its own older main) and compiled about 9 % of the Metal sources twice, so it is not taken; its measurements are in the entry. Checked on an M6 (12 cores, 16 GB, J=12, empty cache, another game running beside it) against main f75ac06: Red Dead Redemption's 3,628 shaders, Mac 54 to 35 s, Mac and iOS 84 s to 53 and 63 s, restored from the cache 11 to 13 s (the headers are made though nothing compiles); 1,920 of Metroid Prime 4: Beyond's shaders 105 to 72 s, 89 s with DMSH_PROCS=6. Peak memory (summed resident size of the process tree, which counts the forks' shared pages once each): Red Dead Redemption 0.45 to 0.8 GB, the Metroid Prime 4 shaders 1.1 to 3.4 GB, 2.0 GB with 6 workers; a worker holds about 35 MB, the rest is J compilers running at once. Identical: Red Dead Redemption's Mac library (15,542 files) apart from the chain version and _b_cas.txt, and its iOS library (11,912 files); the author's 173,316 files of Ocarina of Time. Tests: test_shader_cache (forked workers share the file), test_shader_toolchain_cache, test_shader_pch, test_nsp_chain, test_docs. The chain version changes (dmsh_build.py), so every game's shaders are translated again once, their Metal compiles reused. Not run: regress.py check (the outputs are the same bytes), a Mac with 8 GB, a whole large map with iOS libraries, a large warm build here. lint_python.py lists one finding outside its baseline, an unused import in dmsh_entry.py, which this does not touch (PR #2255) Co-authored-by: cashcon57 <24542086+cashcon57@users.noreply.github.com>
|
Thank you for this, and @tobiashenn for the M3 Pro run. The same problem is now solved on main by 8b55ebb (PR #2255: forked worker processes for the finish step), so I am closing this one without merging it. Why that design: both were run on one Mac (M6, 12 cores, 16 GB, Your measurements are kept: Ocarina of Time's map on the M5 Max (3,002 to 1,298 s), the scheduling-only figure, and the M3 Pro's time and memory are in the reference entry, A shader build's Python finishes one shader at a time. If the largest-first chunk scheduling still gains on top of the workers on your Mac, a measurement of that alone would be welcome. |
…no shader waits for a batch: Ocarina of Time's whole Mac map, built cold on an M5 Max with 18 cores, takes 1,298 s instead of 3,002 # Conflicts: # dm/gfx/nvn/dmsh_chain.h
…ur of seedds#2255, on main as 8b55ebb
What and why
On an M5 Max with 18 cores, a cold shader build left about half the cores idle whatever
Jwas, anddmsh_build.py's own process sat at one full core the whole time. There were two causes. Each shader needs about 40 ms of the builder's own Python, and one process runs that one shader at a time under the GIL. On top of that, every batch of4 × Jshaders waited for its slowest shader before the next one started.The build now runs as
DMSH_PROCScopies of itself (defaultJ / 3, so 6 atJ=18;DMSH_PROCS=1keeps the old single process). Each copy builds a share of one phase and stages its outputs in the same cache, and the build that started them writes the library as before. Within a process, the misses are translated in chunks of 8, largest first, and each shader is finished as soon as its own chunk is translated, so no worker waits for a batch. Paired vertex shaders still run after every other shader.This answers the open note under Rewrites that try every character of a large source, which asked to measure worker processes again on a machine with more cores. The new entry is A shader build's Python finishes one shader at a time.
Checked
0400486024DEC000v131072, 42,848 shaders): 3,002 s before, 1,298 s after. CPU went from 25,974 s to 20,859 s._b.jsonand the digests in_b_cas.txt.c1_full.tsvandcb_extent.tsvmatch apart from their header line.dm/tools/teststhat cover the build pass. I updatedtest_shader_toolchain_cache.pyto run the new scheduler instead of the batch loop.test_dmsh_abi(test_no_new_abi_literals) andtest_nsp_incremental(test_provisional_run_invalidates_derivation) fail the same way on main.lint_python.py: 0 new findings.DOTNET_TieredPGO=0, and compiling a library straight from its source. The last one also gives other bytes.regress.py check: I don't have it. Ocarina of Time is the only game on this Mac. The change only reorders the work and gives the same bytes, so the whole-map byte comparison above is what I'd offer instead.IOSOUT), whose libraries go through the same workers.Docs
docs/reference/shaders.mdand in Ocarina of Time's note, anddocs_symptoms.pywas run.dmsh_chain.py --headerwas run anddmsh_chain.his part of the change.